#!/usr/bin/env python
# coding: utf-8
import os
from os.path import dirname, exists, expanduser, isdir, join, splitext
import numpy as np
import pandas as pd
from hic import load_hic
import joblib

print("加载 Health Insurance Costs 数据\n")

dataset = load_hic()

X = dataset.data
y = dataset.target
headers = dataset.feature_names

print("数据集")
print("已加载 %d 训练数据集, 包含 %d 个特征" % X.shape)
print("预测目标保险客户理赔支出\n")

print("数据集预处理")
categorical_features = ["sex", "region", "smoker"]
X_cat = pd.get_dummies(X[categorical_features])
X = X.drop(categorical_features, axis=1)
X = pd.concat([X, X_cat], axis=1)

print("\n训练模型")
print("LinearRegression线性回归模型\n")
# from sklearn.linear_model import LinearRegression
# reg = LinearRegression()
# from sklearn.linear_model import Ridge
# reg = Ridge()
# from sklearn.linear_model import Lasso
# reg = Lasso()
# from sklearn.linear_model import ElasticNet
# reg = ElasticNet()
# from sklearn.linear_model import RidgeCV
# reg = RidgeCV()
# from sklearn.linear_model import SGDRegressor
# reg = SGDRegressor()
from sklearn.svm import SVR
reg = SVR(kernel='rbf')

model = reg.fit(X, y)

joblib.dump(reg, 'hic-SVR-rbf.pkl')

# 训练结果
print("\n评分")
print(model.score(X, y))
